using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using UwinEducation.Shared.Enums;

namespace UwinEducation.Domain.Entities
{
    /// <summary>
    /// 学生缴费实体
    /// </summary>
    [Table("student_payments")]
    public class StudentPayment : EntityBase
    {
        /// <summary>
        /// 学生缴费ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 学生ID
        /// </summary>
        public Guid StudentId { get; set; }

        /// <summary>
        /// 教师课表组ID
        /// </summary>
        public Guid TeacherScheduleGroupId { get; set; }

        /// <summary>
        /// 总价
        /// </summary>
        [Column(TypeName = "decimal(18,2)")]
        public decimal TotalAmount { get; set; }
        /// <summary>
        /// 学生单价(元/课时)
        /// </summary>
        [Column(TypeName = "decimal(18,2)")]
        public decimal UnitPrice { get; set; }
        /// <summary>
        /// 已缴费金额
        /// </summary>
        [Column(TypeName = "decimal(18,2)")]
        public decimal PaidAmount { get; set; }

        /// <summary>
        /// 缴费状态
        /// </summary>
        public PaymentStatus Status { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }


        /// <summary>
        /// 关联的学生
        /// </summary>
        public virtual Student Student { get; set; }


        /// <summary>
        /// 创建学生缴费记录
        /// </summary>
        public static StudentPayment Create(
            Guid studentId,
            Guid teacherScheduleGroupId,
            decimal totalAmount,
            decimal paidAmount = 0,
            string remarks = null)
        {
            return new StudentPayment
            {
                Id = Guid.NewGuid(),
                StudentId = studentId,
                TeacherScheduleGroupId = teacherScheduleGroupId,
                TotalAmount = totalAmount,
                PaidAmount = paidAmount,
                Status = PaymentStatus.PartiallyPaid,
                Remarks = remarks,
                CreatedAt = DateTime.Now
            };
        }
    }
}